package com.etc.util;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexUtil {
    /**
     * 手机号校验
     */
    private static String telRegex = "0?(13|14|15|18|17)[0-9]{9}";
    /**
     * 邮箱校验
     */
    private static String emailRegex = "\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}";
    /**
     * 由字母数字下划线组成且开头必须是字母，不能超过16位
     */
    private static String usernameRegex = "[a-zA-Z]{1}[a-zA-Z0-9_]{1,15}";

    public static int validateName(String loginName) {
        if (loginName.matches(telRegex)) {
            return 2;
        } else if (loginName.matches(emailRegex)) {
            return 3;
        } else if (loginName.matches(usernameRegex)) {
            return 1;
        }
        return -1;
    }

    /*public static String cutString(String string, String reg) {
        List<String> list = new ArrayList<>();
        List<String> extvounoLists = new ArrayList<>();
        Pattern pattern = Pattern.compile(reg);
        Matcher m = pattern.matcher(string);
        while (m.find()) {
            int i = 1;
            list.add(m.group(i));
            i++;
        }
        for (String s : list) {

        }
    }*/
    public static void main(String[] args) {
        /*String tel = "";
        boolean flag = tel.matches(telRegex);
        //System.out.println(flag);
        String email = "747432@qq.com";
        //System.out.println(email.matches(emailRegex));
        String username = "";
        System.out.println(username.matches(usernameRegex));*/
    }
}
